package com.redepronik.negosys.invfac.entity;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import org.hibernate.annotations.IndexColumn;

/**
 * The persistent class for the credito database table.
 * 
 */
@Entity
@Table(schema = "invfac", name = "credito")
@NamedQuery(name = "Credito.findAll", query = "SELECT c FROM Credito c")
public class Credito implements Serializable {
	private static final long serialVersionUID = 1L;

	@Id
	@SequenceGenerator(allocationSize = 1, name = "CREDITO_CREDITOID_GENERATOR", sequenceName = "INVFAC.CREDITO_CREDITOID_SEQ")
	@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "CREDITO_CREDITOID_GENERATOR")
	@Column(unique = true, nullable = false)
	private Integer creditoid;

	@Column(nullable = false, precision = 20, scale = 10)
	private BigDecimal interes;

	@Column(nullable = false)
	private Integer meses;

	@Column(nullable = false, precision = 20, scale = 10)
	private BigDecimal monto;

	@Column(nullable = false)
	private Boolean pagado;

	// bi-directional many-to-one association to Egreso
	@OneToOne
	@JoinColumn(name = "egresoid", nullable = false)
	private Egreso egreso;

	// bi-directional many-to-one association to Detallecredito
	@OneToMany(orphanRemoval = true, cascade = CascadeType.ALL, mappedBy = "credito")
	@IndexColumn(name = "orden", base = 1)
	private List<Detallecredito> detallecreditos;

	// bi-directional many-to-one association to Garante
	@OneToMany(orphanRemoval = true, cascade = CascadeType.ALL, mappedBy = "credito")
	private List<Garante> garantes;

	public Credito() {
	}

	public Detallecredito addDetallecredito(Detallecredito detallecredito) {
		getDetallecreditos().add(detallecredito);
		detallecredito.setCredito(this);

		return detallecredito;
	}

	public Garante addGarante(Garante garante) {
		getGarantes().add(garante);
		garante.setCredito(this);

		return garante;
	}

	public Integer getCreditoid() {
		return this.creditoid;
	}

	public List<Detallecredito> getDetallecreditos() {
		return this.detallecreditos;
	}

	public Egreso getEgreso() {
		return this.egreso;
	}

	public List<Garante> getGarantes() {
		return this.garantes;
	}

	public BigDecimal getInteres() {
		return this.interes;
	}

	public Integer getMeses() {
		return this.meses;
	}

	public BigDecimal getMonto() {
		return this.monto;
	}

	public Boolean getPagado() {
		return this.pagado;
	}

	public Detallecredito removeDetallecredito(Detallecredito detallecredito) {
		getDetallecreditos().remove(detallecredito);
		detallecredito.setCredito(null);

		return detallecredito;
	}

	public Garante removeGarante(Garante garante) {
		getGarantes().remove(garante);
		garante.setCredito(null);

		return garante;
	}

	public void setCreditoid(Integer creditoid) {
		this.creditoid = creditoid;
	}

	public void setDetallecreditos(List<Detallecredito> detallecreditos) {
		this.detallecreditos = detallecreditos;
	}

	public void setEgreso(Egreso egreso) {
		this.egreso = egreso;
	}

	public void setGarantes(List<Garante> garantes) {
		this.garantes = garantes;
	}

	public void setInteres(BigDecimal interes) {
		this.interes = interes;
	}

	public void setMeses(Integer meses) {
		this.meses = meses;
	}

	public void setMonto(BigDecimal monto) {
		this.monto = monto;
	}

	public void setPagado(Boolean pagado) {
		this.pagado = pagado;
	}

}